package user

import (
	"context"
	"net/http"
)

const AppName = "user"

type Service interface {
	// 用户登录
	Login(context.Context, *LoginRequest) (*Session, error)

	// 用户登出
	Logout(context.Context, *LogoutRequest) error

	// 判断是否登录
	CheckIsLogin(context.Context, *CheckIsLoginRequest) error
}

func NewLoginRequest() *LoginRequest {
	return &LoginRequest{}
}

func NewLoginRequestFromBasicAuth(r *http.Request) *LoginRequest {
	user, pass, _ := r.BasicAuth()
	return &LoginRequest{
		Name: user,
		Pass: pass,
	}
}

type LoginRequest struct {
	Name string
	Pass string
}

func NewLogoutRequest() *LogoutRequest {
	return &LogoutRequest{}
}

type LogoutRequest struct {
	Username string `json:"username"`
}

func NewCheckIsLogin(username, session string) *CheckIsLoginRequest {
	return &CheckIsLoginRequest{
		Username:  username,
		SessionId: session,
	}
}

type CheckIsLoginRequest struct {
	Username  string
	SessionId string
}
